import PureConsumerList from '../components/consumer-list';
import {fetchConsumerListByService} from 'actions/service';
import { getFetchStatus } from 'actions/util';
import * as ReactRedux from 'react-redux';
import * as React from 'react';

const mapStateToProps = (state) => {
  return {
    isFetching: getFetchStatus(state, fetchConsumerListByService),
    consumerList: state.consumerListByService
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    initFetch: (serviceId) => {
      dispatch(fetchConsumerListByService(serviceId));
    }
  };
};

class ConsumerList extends React.Component {

  componentDidMount() {
    this.props.initFetch(this.props.serviceId);
  }

  render() {
    return <PureConsumerList {...this.props}/>;
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(ConsumerList);
